package com.shrct.businessprocess.project.impl;

import com.google.common.base.Objects;
import com.shrct.businessprocess.project.RCSalesCommissionOverflowConfigItem;
import com.shrct.businessprocess.project.RCSalesCommissionYearConfig;
import com.shrct.businessprocess.project.impl.RCSalesCommissionYearConfigImpl;
import com.shrct.businessprocess.project.proxy.RCSalesCommissionOverflowConfigItemProxy;
import com.uniquesoft.uidl.validation.Validates;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("RCSALESCOMMISSIONOVERFLOWCONFIGITEM_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "rcsalescommissionoverflowconfigitem")
public class RCSalesCommissionOverflowConfigItemImpl extends BaseModelObject implements RCSalesCommissionOverflowConfigItem {
  public RCSalesCommissionOverflowConfigItemImpl() {
    super();
  }
  
  public RCSalesCommissionOverflowConfigItemImpl(final RCSalesCommissionYearConfig config) {
    super();
    this.config = config;
  }
  
  @JoinColumn(name = "config_id")
  @ManyToOne(targetEntity = RCSalesCommissionYearConfigImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCSalesCommissionYearConfig config;
  
  public RCSalesCommissionYearConfig getConfig() {
    return this.config;
  }
  
  public RCSalesCommissionOverflowConfigItem setConfig(final RCSalesCommissionYearConfig config) {
    this.config = config;
    return this;			
    
  }
  
  private Double multiple;
  
  public Double getMultiple() {
    return this.multiple;
  }
  
  public RCSalesCommissionOverflowConfigItem setMultiple(final Double multiple) {
    this.multiple = multiple;
    return this;			
    
  }
  
  private Double rate;
  
  public Double getRate() {
    return this.rate;
  }
  
  public RCSalesCommissionOverflowConfigItem setRate(final Double rate) {
    this.rate = rate;
    return this;			
    
  }
  
  public void update(final Procedure1<? super RCSalesCommissionOverflowConfigItem> updater) {
    updater.apply(this);
    this.checkValid();
  }
  
  public void checkValid() {
    boolean _notEquals = (!Objects.equal(this.multiple, null));
    Validates.Assert(_notEquals, "\u500D\u6570\u4E0D\u80FD\u4E3A\u7A7A");
    boolean _notEquals_1 = (!Objects.equal(this.rate, null));
    Validates.Assert(_notEquals_1, "\u8D85\u989D\u5956\u6BD4\u4F8B\u4E0D\u80FD\u4E3A\u7A7A");
  }
  
  public static RCSalesCommissionOverflowConfigItem create(final RCSalesCommissionYearConfig config, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.project.RCSalesCommissionOverflowConfigItem rCSalesCommissionOverflowConfigItem = new com.shrct.businessprocess.project.impl.RCSalesCommissionOverflowConfigItemImpl(
    	config
    );
    objectFactory.create(rCSalesCommissionOverflowConfigItem);
    return rCSalesCommissionOverflowConfigItem;			
    
  }
  
  public static RCSalesCommissionOverflowConfigItem createRCSalesCommissionOverflowConfigItemImpl(final RCSalesCommissionYearConfig config, final IObjectFactory objectFactory, final Procedure1<RCSalesCommissionOverflowConfigItem> init) {
    com.shrct.businessprocess.project.RCSalesCommissionOverflowConfigItem rCSalesCommissionOverflowConfigItem = new com.shrct.businessprocess.project.impl.RCSalesCommissionOverflowConfigItemImpl(
    	config
    );
    objectFactory.create(rCSalesCommissionOverflowConfigItem);
    init.apply(rCSalesCommissionOverflowConfigItem);
    
    return rCSalesCommissionOverflowConfigItem;			
    
  }
  
  public RCSalesCommissionOverflowConfigItemProxy toProxy() {
    com.shrct.businessprocess.project.proxy.RCSalesCommissionOverflowConfigItemProxy proxy = new com.shrct.businessprocess.project.proxy.RCSalesCommissionOverflowConfigItemProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
